package com.gitee.minimalismstyle.fresh.common.data.jdbc.config

import com.gitee.minimalismstyle.fresh.common.data.jdbc.beetl.BeetlDataAccessStrategy
import org.beetl.sql.core.SQLManager
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.jdbc.core.convert.DataAccessStrategy
import org.springframework.data.jdbc.core.convert.JdbcConverter
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext
import org.springframework.data.relational.core.dialect.Dialect
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations

@Configuration(proxyBeanMethods = false)
class BeetlJdbcConfig(val sqlManager: SQLManager) {

    @Bean
    fun dataAccessStrategyBean(operations: NamedParameterJdbcOperations?, jdbcConverter: JdbcConverter?,
                               context: JdbcMappingContext?, dialect: Dialect?): DataAccessStrategy? {
        return BeetlDataAccessStrategy.createCombinedAccessStrategy(context!!, jdbcConverter!!, operations!!, sqlManager, dialect!!)
    }
}